<%--
  Created by IntelliJ IDEA.
  User: 我爱陈果果
  Date: 2020/8/16
  Time: 10:15
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="basePath.jsp"%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>分配权限</title>
</head>
<body style="text-align: center;">

<h2>权限修改页面！所有角色权限信息如下：</h2>
<div>
    <c:forEach items="${roles}" var="role">
        <a href="${basePath}auth/queryAllAuthority?id=${role.id}&roleDesc=${role.roleDesc}">${role.roleDesc}</a> |
    </c:forEach>
</div>
<table border="1" style="margin: auto;">
    <caption>${empty sysRole.roleDesc ? '所有权限':sysRole.roleDesc}</caption>
    <tr>
        <th>名称</th>
        <th>资源路径</th>
        <th>是否拥有权限</th>
    </tr>
    <c:forEach items="${resourcesMap}" var="resourcesEntry">
        <c:set var="resource" value="${resourcesEntry.key}"/>
        <c:set var="isResource" value="${resourcesEntry.value}"/>
        <tr>
            <td>${resource.userName}</td>
            <td>${resource.resUrl}</td>
            <td>
                <c:if test="${not empty sysRole.roleDesc}">
                    <input type="radio" onclick="addAuthority(${sysRole.id}, ${resource.id},${sysRole.roleDesc}, this)" name="has_+${resource.id}" ${isResource==1?'checked':''} value="1"/>是
                    <input type="radio" onclick="addAuthority(${sysRole.id}, ${resource.id},${sysRole.roleDesc}, this)" name="has_+${resource.id}" ${isResource==0?'checked':''} value="0"/>否
                </c:if>
            </td>
        </tr>
    </c:forEach>
</table>

<script>
    function addAuthority(roleId, resourcesId, roleDesc, obj) {
        window.location.href = "${basePath}auth/addAuthority?roleId="+roleId+"&resourcesId="+resourcesId+"&has="+obj.value+"&roleDesc="+roleDesc;
    }
</script>
</body>
</html>
